package retrofit;

import com.yunshl.yunshllibrary.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/***
 * 功能描述:
 * 作者:qiujialiu
 * 时间:2016/12/23
 * 版本:1.0
 ***/

class NeededFilterUrl {
    public static String rule = ".";
    public static Pattern pattern = Pattern.compile(rule);
    public static List<String> filter = new ArrayList<>();
    private static StringBuilder builder = new StringBuilder();

    static {

        if (filter != null && filter.size() > 0) {
            for (String s : filter) {
                s = s.replaceAll("/v[0-9]+/", "/v[0-9_]+/");
                builder.append("(").append(s).append(")|");
            }
            builder.delete(builder.length() - 1, builder.length());
            LogUtils.w("FilterUrl", builder.toString());
            rule = ".*(" + builder + ").*";
            LogUtils.w("FilterUrl", "rule:" + rule);
            pattern = Pattern.compile(rule);
        }
    }

    public static boolean needFilter(String url) {
        try {
            boolean b = (pattern.matcher(url).matches());
            LogUtils.w("FilterUrl", "is need to filter " + b);
            return b;
        } catch (Exception e) {
            return false;
        }
    }
}
